<?php
/**
 * 优惠券图片统一调用函数//zmr>v30
 *
 *
 *
 */

defined('InShopNC') or exit('Access Invalid!');

/**
 * 取得商品缩略图的完整URL路径，接收商品信息数组，返回所需的商品缩略图的完整URL
 *
 * @return string
 */
function vthumb($voucher = array(), $type = ''){
    $type_array = explode(',_', ltrim(GOODS_IMAGES_EXT, '_'));
    if (!in_array($type, $type_array)) {
        $type = '240';
    }
    if (empty($voucher)){
        return UPLOAD_SITE_URL.'/'.defaultGoodsImage($type);
    }
    if (empty($voucher['voucher_t_customimg'])) {
        return UPLOAD_SITE_URL.'/'.defaultGoodsImage($type);
    }
    $search_array = explode(',', GOODS_IMAGES_EXT);
    $file = str_ireplace($search_array,'',$voucher['voucher_t_customimg']);
    //取店铺ID
    $store_id = $voucher['voucher_t_store_id'];
    $file = $type == '' ? $file : str_ireplace('.', '_' . $type . '.', $file);
    if (!file_exists(BASE_UPLOAD_PATH.'/'.ATTACH_VOUCHER.'/'.$store_id.'/'.$file)){
        return UPLOAD_SITE_URL.'/'.defaultGoodsImage($type);
    }
    $thumb_host = UPLOAD_SITE_URL.'/'.ATTACH_VOUCHER;
    return $thumb_host.'/'.$store_id.'/'.$file;

}

?>